package com.cskaoyan.mall.controller.promotion;
import com.cskaoyan.mall.bean.Coupon;
import com.cskaoyan.mall.bean.bo.CouponBo;
import com.cskaoyan.mall.bean.vo.ResultVO;
import com.cskaoyan.mall.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/coupon")
public class CouponController {
    @Autowired
    CouponService couponService;
    @RequestMapping("list")
    public ResultVO queryCoupon(Integer page,Integer limit,String name,Short type,Short status,String sort,String order){
        List<Coupon> coupons = couponService.queryCouponList(page,limit,name,type,status,sort,order);
        HashMap<String, Object> map = new HashMap<>();
        map.put("items",coupons);
        map.put("total",coupons.size());
        return ResultVO.ok(map);
    }

    @PostMapping("update")
    public ResultVO updateCoupon(@RequestBody Coupon coupon){
        Coupon couponVo = couponService.updateCoupon(coupon);
        return ResultVO.ok(coupon);
    }

    @RequestMapping("read")
    public ResultVO queryCoupon(Integer id){
        Coupon coupon = couponService.queryCouponById(id);
        return ResultVO.ok(coupon);
    }

    @RequestMapping("listuser")
    public ResultVO queryListUser(Integer page,Integer limit,Integer couponId,String sort,String order){
        Map<String,Object> map = couponService.queryCouponUserList(page,limit,couponId,sort,order);
        return ResultVO.ok(map);
    }

    @PostMapping("delete")
    public ResultVO deleteCoupon(@RequestBody Coupon coupon){
        couponService.deleteCoupon(coupon);
        return ResultVO.ok();
    }

    @PostMapping("create")
    public ResultVO createCoupon(@RequestBody Coupon coupon){
        Coupon couponVo = couponService.createCoupon(coupon);
        return ResultVO.ok(couponVo);
    }




}
